home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: bcalbridge@dcccd.edu (Bob Calbridge)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: 8 Queens prog help
- Date: 20 Apr 1996 13:34:50 -0500
- Organization: D C C C D
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4lbaoa$lku@solutions.solon.com>
- References: <4l87ud$73u@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Mike Mitchell <72724.2067@CompuServe.COM> wrote:
-
- >Hi All!
-
- >Need some C help this week. I'm currently working on a program
- >called "Eight Queens". Basically, I have to place 8 queen chess
- >pieces on an 8x8 chess board without them checking one another.
- >The instructer wants us to use a "backtracking algorithm" (i.e. a
- >tree structure) to accomplish this. My thoughts thus far are to
- >place my first queen randomly and mark that space with a 'Q'
- >character and then mark off all the squares in its legal paths
- >(all adjacent squares vertical, horizontal, and diagonal to the
- >ends of the board) with an 'X' character. Board is initialized
- >to Nulls.
-
- >When the next queen piece is placed I will check to see if
- >another queen is in one of its paths. If there isn't I will
- >place the piece and mark off its paths otherwise I will return
- >the square to NULL and move to the next NULL square.
-
- >Am I approaching this the right way or should I be handling this
- >another way? Can someone explain how a tree structure
- >accomplishes this?
-
- >We did a similar problem in class using the knight piece and its
- >legal moves. Well, needless to say the number of legal moves a
- >queen can make, make this problem a little more difficult.
-
- Hmmm. Not sure what you mean by a tree structure in this instance.
- The only time I've tackled this problem I used recursion and brute
- force. The method you speak of is probably a bit faster than mine but
- mine did produce all non-unique solutions where yours just seems to
- produce one random solution.
-
- It seems to me that if each subsequent piece placement finds a null
- square there should no reason to check your paths to see if there's
- conflict. Otherwise it wouldn't be a null square to begin with.
-
- I'm not sure why you say that the queen's problem is more difficult
- than the knight's problem. I'm assuming that it was a matter of
- placing eight knights on the board? It would seem to me that the
- prospect of mapping eight elimination squares in a non-linear
- arrangement is more complex than the straight paths a queen moves on.
- Just wait 'til you try to move a knight from a single starting point
- to all 64 squares without revisiting any squares. :-(
-
- Bob
- Bob Calbridge = bcalbridge@dcccd.edu
- Senior Network Systems Programmer
- Postmaster, Cook, Bottle Washer
-